package DynamicProgramming;

import java.util.Arrays;
import java.util.Scanner;

class Cf1203 implements Comparable<Cf1203>
{	public int start, end;
	public Cf1203(int S, int E)
	{	start=S;end=E;
	}
	@Override
	public int compareTo(Cf1203 o)
	{	return (end!=o.end)?(end-o.end):(o.start-start);
	}
}
public class P1203
{	public static void main(String[] args)
	{	Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		Cf1203 cf[]=new Cf1203[n];
		for (int i=0;i<n;i++)
			cf[i]=new Cf1203(in.nextInt(), in.nextInt()+1);
		Arrays.sort(cf);
		
		int count=1;
		Cf1203 cur=cf[0];
		for (int i=1;i<n;i++)
			if (cf[i].end>cur.end)
				if (cf[i].start>=cur.end)
				{	count++;
					cur=cf[i];
				}
		System.out.println(count);
		in.close();
	}
}
